/*
  (C) 2005 Adam D. Bradley

  This program is free software; you can redistribute it and/or
  modify it under the terms of Version 2 of the GNU General Public 
  License.
  
  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  General Public License for more details.
  
  You should have received a copy of the GNU Library General Public
  License along with this library; if not, write to the Free
  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

package step;

import java.net.URI;
import snobject.snCommand;
import step.SocketNode;

/**
 * A ReceiverSocketNode is where data enters the local STEP graph from
 * a remote STEP graph via the network.  Conceptually, it is the parent
 * side of a network STEP link.
 */
public abstract class ReceiverSocketNode extends SocketNode
{
	protected ReceiverSocketNode(String id, String fromID, URI fromURI) 
	{
		super(id);
		FromID = fromID;
		FromURI = fromURI;
	}

	protected ReceiverSocketNode(String fromID, URI fromURI) {
		super();
		FromID = fromID;
		FromURI = fromURI;
	}

	/* For non-HTTP sockets, you will want to override this... */
	protected void ClearEvaluatedFlags() throws EvaluationFailure {
		super.ClearEvaluatedFlags();
		http.Request req = http.Request.POST(FromURI, 
						     snCommand.CLEAR,
						     null, null);
		req.addHeader("From", ID);
		req.addHeader("To", FromID);
		http.Client.Perform_nb(req);
	}

	/* For non-HTTP sockets, you will want to override this... */
	protected void SetWanted(boolean v) throws EvaluationFailure {
		super.SetWanted(v);
		http.Request req = http.Request.POST(FromURI,
						     ((v)
						      ?snCommand.WANT
						      :snCommand.DONTWANT),
						     null, null);
		req.addHeader("From", ID);
		req.addHeader("To", FromID);
		http.Client.Perform_nb(req);
	}

	protected String FromID;
	protected URI FromURI;
}

